package com.java2207.group1.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.java2207.group1.bo.EquipmentsBo;
import com.java2207.group1.pojo.Equipments;
import com.java2207.group1.service.EquipmentsService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 * @author lz
 * @Date 2022/7/27 19:29
 */
@Component
@Scope("prototype")
public class WebEquipmentsListener extends AnalysisEventListener<EquipmentsBo> {
    @Autowired
    EquipmentsService equipmentsService;


    @Override
    public void invoke(EquipmentsBo data, AnalysisContext analysisContext) {
        System.out.println(data);
        Equipments equipments = new Equipments();
        //student.setName(data.getName());
        // 属性拷贝
        BeanUtils.copyProperties(data, equipments);
        equipmentsService.addEquipment(equipments);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
